package com.lvcoding.sec3.secdemo3.validatecode.img;

import com.lvcoding.sec3.secdemo3.validatecode.parent.AbstraceValidateCodeProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;

@Component
public class ImgCodeProcessor extends AbstraceValidateCodeProcessor<ImgCode> {

    @Override
    protected void send(ServletWebRequest request, ImgCode validateCode) throws Exception {
        // 将图片写入到输出流
        assert request.getResponse() != null;
        ImageIO.write(validateCode.getImage(), "JPEG", request.getResponse().getOutputStream());
    }
}
